'''
modified the code from this website:
http://www.daniweb.com/forums/thread39109.html#
'''
   

def N_Gram(N,text):
    NList = []                    
    if N> 1:
        space = " " * (N-1)      
        text =  text 

    for i in range( len(text) - (N - 1) ):
        NList.append(text[i:i+N])
    return NList                    
'''
for i in range(5):
    print N_Gram(i+1,"text")
'''
nList = N_Gram(6,"   asdfag546y$% ^^%$ %^^  hello Didier  344544 5#$% %@ @")
for ngram in iter(nList):
    print '"' + ngram + '"'     
